<?php
/*
 * @Author: your name
 * @Date: 2020-10-19 17:16:32
 * @LastEditTime: 2020-12-17 12:01:53
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙数据设置验证器
 * @FilePath: /special/application/adminapiv3/validate/FirewallSetValidate.php
 */
namespace app\adminapiv3\validate;

use think\Validate;

class FirewallSetValidate extends Validate
{
    protected $rule = [
        //主机id
        'host_id|主机ID' => 'require|regex:^\d+(,\d+){0,29}$',
        //取消防火墙接管时间
        'uncontrol_firewall_etime|取消防火墙接管时间' => 'integer|length:10',
        //系统
        'os|主机系统类型' => 'require|in:1,2',
        /*-------linux防火墙参数----*/
        //开关 1开启 0关闭
        'main_switch|防火墙开关' => 'require|in:1,0',
        //入站 1开启 0关闭
        'input|入站默认处理方式' => 'require|in:1,0',
        //出站 1开启 0关闭
        'output|出站默认处理方式' => 'require|in:1,0',
        //路由转发 1开启 0关闭
        'forward|路由转发默认处理方式' => 'require|in:1,0',
        /*-------windows防火墙参数----*/
        //私网主开关
        'private_main_switch|专用网络开关' => 'require|in:1,0',
        //公网主开关
        'public_main_switch|公共网络开关' => 'require|in:1,0',
        //域主开关
        'domain_main_switch|域网络开关' => 'require|in:1,0',
        //私网入站开关
        'private_input|专用网络入站默认处理方式' => 'require|in:1,0',
        //公网入站开关
        'public_input|公用网络入站默认处理方式' => 'require|in:1,0',
        //域入站开关
        'domain_input|域网络入站默认处理方式' => 'require|in:1,0',
        //私网出站开关
        'private_output|专用网络出站默认处理方式' => 'require|in:1,0',
        //公网出站开关
        'public_output|公用网络出站默认处理方式' => 'require|in:1,0',
        //域出站开关
        'domain_output|域网络出站默认处理方式' => 'require|in:1,0',
    ];

    //错误消息
    protected $message = [
        'os.in' => '主机系统类型格式错误',
        'main_switch.in' => '防火墙开关格式错误',
        'input.in' => '入站默认处理方式格式错误',
        'output.in' => '出站默认处理方式格式错误',
        'forward.in' => '路由转发默认处理方式格式错误',
        'private_main_switch.in' => '专用网络开关格式错误',
        'public_main_switch.in' => '公共网络开关格式错误',
        'domain_main_switch.in' => '域网络开关格式错误',
        'private_input.in' => '专用网络入站默认处理方式格式错误',
        'public_input.in' => '公用网络入站默认处理方式格式错误',
        'domain_input.in' => '公用网络入站默认处理方式格式错误',
        'private_output.in' => '专用网络出站默认处理方式格式错误',
        'public_output.in' => '公用网络出站默认处理方式格式错误',
        'domain_output.in' => '域网络出站默认处理方式格式错误',
    ];

    protected $scene = [
        //linux设置
        'linuxSet' => ['main_switch','input','output','forward','host_id'],
        //windwos设置
        'windowsSet' => ['private_main_switch','public_main_switch','domain_main_switch','private_input','public_input','domain_input','private_output','public_output','domain_output','host_id'],
        //接管防火墙
        'controlFirewall' => ['host_id'],
        //取消接管防火墙
        'uncontrolFirewall' => ['host_id', 'uncontrol_firewall_etime'],
        //系统
        'os' => ['os']
    ];
}